package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ClassificationofdoctorsBean;
import com.example.myapplication.ShuJu.InquirycaseBean;
import com.example.myapplication.hospital.ConsultationpageActivity;
import com.example.myapplication.hospital.DoctordetailsActivity;
import com.google.gson.Gson;

import java.util.List;

public class InquirycaseApter extends RecyclerView.Adapter<InquirycaseApter.Myhot> {
    private Context context;
    private String  TAG ;
    private List<InquirycaseBean.RowsBean> list;

    public InquirycaseApter(Context context, List<InquirycaseBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public InquirycaseApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_inquirycase, null);
        return new InquirycaseApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull InquirycaseApter.Myhot holder, int position) {
     /*   if(list.get(position).getDoctor()!=null){
            if (!TextUtils.isEmpty(list.get(position).getDoctor().getAvatar())) {
                Glide.with(context).load(TokenBean.IP + list.get(position).getDoctor().getAvatar()).into(holder.img);
            }
            if (!TextUtils.isEmpty(list.get(position).getDoctor().getName())) {
                holder.name.setText(list.get(position).getDoctor().getName());
            }
            if (TextUtils.isEmpty(list.get(position).getQuestion())){
                holder.jobName.setText(list.get(position).getQuestion());
            }else {
                holder.jobName.setText("案例描述");
            }
        }*/

        if(list.get(position).getDoctor()!=null){
            if (!TextUtils.isEmpty(list.get(position).getDoctor().getAvatar())) {
                Glide.with(context).load(TokenBean.IP + list.get(position).getDoctor().getAvatar()).into(holder.img);
            }
            if (!TextUtils.isEmpty(list.get(position).getDoctor().getName())) {
                holder.name.setText(list.get(position).getDoctor().getName());
            }else {
                holder.name.setText("暂无信息");
            }
            if (!TextUtils.isEmpty(list.get(position).getQuestion())){
                holder.jobName.setText(list.get(position).getQuestion());
            }else {
                holder.jobName.setText("暂无信息");
            }
        }


        //案例详情页面
        holder.re_medic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DoctordetailsActivity.class);
                Gson gson = new Gson();
                String Bean = gson.toJson(list.get(position));
                intent.putExtra(Commom.DOCTORDETAILSBANE,Bean);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : 9;
    }

    class Myhot extends RecyclerView.ViewHolder {

        private final TextView name;
        private final ImageView img;
        private final TextView jobName;
        private final RelativeLayout re_medic;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            jobName = itemView.findViewById(R.id.jobName);
            re_medic = itemView.findViewById(R.id.re_medic);
        }
    }
}


